#ifndef BLOBDETECTOR_H
#define BLOBDETECTOR_H

/********** Library Includes **************************************************/

#include <opencv/cv.h>
#include <opencv/highgui.h>

/********** Classes ***********************************************************/

class BlobDetector {
public:
	enum Color {
		NO_COLOR,
		COLOR_GREEN,
		COLOR_BLUE
	};
	
	enum BlobCategory {
		UNCATEGORIZED,
		ROBOT_LEFT,
		ROBOT_RIGHT
	};
	
	struct Blob {
		cv::Point center;
		int size;
		Color color;
		BlobCategory category;
	};
	
	BlobDetector();
	
	/**
	 * Uses the set thresholds to identify all blobs in the given image.
	 */
	std::vector<Blob> findBlobs(const cv::Mat &image);
	
	/**
	 * Filters the given blobs for the largest green and the two largest red.
	 */
	std::vector<Blob> filterForLargest(const std::vector<Blob> &allBlobs) const;
	
	/**
	 * Categorizes each of the given blobs into one of the three blob categories
	 * given by the enum BlobCategory.
	 */
	std::map<BlobCategory, Blob> categorize(const std::vector<Blob> &largest) const;
	
	void showDebug(const std::map<BlobCategory, Blob> &) const;
	
	std::map<BlobCategory, cv::Point> getPoints(const cv::Mat &image);

protected:
	void filter(const cv::Mat &src, cv::Mat &dst, Color color) const;
	
	std::vector<Blob> findBlobs(const cv::Mat& rgbImage, Color color);

private:
	double euclidean(cv::Point p1, cv::Point p2) const;

	cv::SimpleBlobDetector m_sbd;
	std::vector<Color> m_colors;
	
	typedef std::vector<Color>::const_iterator ColorIterator;
};

#endif
